//
//  EaseStartView.m
//  test
//
//  Created by kepuG on 17/1/20.
//  Copyright © 2017年 text. All rights reserved.
//

#import "EaseStartView.h"

@interface EaseStartView ()

@property (strong ,nonatomic) UIImageView *bgImageView;


@end


@implementation EaseStartView


+ (instancetype) startView{
    UIImage *logImage = [UIImage imageNamed:@"logo_coding_top@2x"];
    return [[self alloc] initWithBgImage:logImage logoIcon:nil descriptionStr:@"hello"];
}

-(instancetype)initWithBgImage:(UIImage*)image logoIcon:(UIImage*)logoIcon descriptionStr:(NSString *)descriptionStr{
    self = [super initWithFrame:kScreen_Bounds];
    if (self) {
        
        UIColor *blackColor = [UIColor blackColor];
        self.backgroundColor = blackColor;
        self.alpha = 1.f;
        _bgImageView = [[UIImageView alloc] initWithFrame:kScreen_Bounds];
        _bgImageView.image = [UIImage imageNamed:@"startPage.jpg"];
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
        _bgImageView.alpha = 0.0;
        
        [self addSubview:_bgImageView];
    }
    return self;
}

-(void)startAnimationWithCompletionBlock:(void (^)(EaseStartView *))completionHandler{
    [kKeyWindow addSubview:self];
    [kKeyWindow bringSubviewToFront:self];
    
    @weakify(self);
    [UIView animateWithDuration:2.0 animations:^{
        @strongify(self);
        self.bgImageView.alpha = 1.0;
//        self.descriptionStrLabel.alpha = 1.0;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.6 delay:0.3 options:UIViewAnimationOptionCurveEaseIn animations:^{
            @strongify(self);
            [self setX:-kScreen_Width];
           // [self setY:-kScreen_Height];
        } completion:^(BOOL finished) {
            @strongify(self);
            [self removeFromSuperview];
            if (completionHandler) {
                completionHandler(self);
            }
        }];
    }];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
